<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue-组件化父子通信案例</title>
</head>

<body>
    <div id="app">
        <h2>父组件：{{num1}}</h2>
        <h2>父组件：{{num2}}</h2>
        <cpn :number1="num1" :number2="num2" @num1change="num1change" @num2change="num2change"></cpn>
    </div>
    <template id="cpn">
        <div>
            <h2>props1:{{number1}}</h2>
            <h2>data1:{{dataNumber1}}</h2>
            <!-- <input type="text" v-model="number1" /> -->
            <!-- <input type="text" v-model="dataNumber1" /> -->
            <input type="text" :value="dataNumber1" @input="numInput1" />
            <h2>props2:{{number2}}</h2>
            <h2>data2:{{dataNumber2}}</h2>
            <!-- <input type="text" v-model="number2" /> -->
            <!-- <input type="text" v-model="dataNumber2" /> -->
            <input type="text" :value="dataNumber2" @input="numInput2" />

        </div>
    </template>
    <script src="./js/vue.min.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                num1: 0,
                num2: 1
            },
            methods:{
                num1change(value){
                    console.log(typeof(value));
                    this.num1=value
                },
                num2change(value){
                    this.num2=value;
                    console.log(typeof(value));

                }
            },
            components: {
                cpn: {
                    template: '#cpn',
                    data() {
                        return {
                            dataNumber1: this.number1,
                            dataNumber2: this.number2
                        }
                    },
                    props: {
                        number1: Number,
                        number2: Number
                    },
                    methods: {
                        numInput1(event) {
                            // 1.将inout中的value赋值到datanumber中
                            this.dataNumber1 = event.target.value;
                            // 2.为了让父组件可以修改值 ，发送一个事件
                            this.$emit('num1change',this.dataNumber1);
                            // 3.同时修饰datanumber2的值为datanumber1的100倍
                            this.dataNumber2 = event.target.value*100;
                            // 4.为了让父组件可以修改值 ，发送一个事件
                            this.$emit('num2change',this.dataNumber2)
                        },
                        numInput2(event) {
                            // 1.将inout中的value赋值到datanumber中
                            this.dataNumber2 = event.target.value;
                            // 2.为了让父组件可以修改值 ，发送一个事件
                            this.$emit('num2change',this.dataNumber2)
                            // 3.同时修饰datanumber1的值为datanumber1的100分之一
                            this.dataNumber1 = event.target.value/100;
                            // 4.为了让父组件可以修改值 ，发送一个事件
                            this.$emit('num1change',this.dataNumber1);
                        }
                    }

                }
            }
        })
    </script>
</body>

</html>